package IO.Writer;

import java.io.FileWriter;
import java.util.Arrays;

/*
* 字符输出流
*
* 注意：一定要刷新缓冲区或者关闭流，否则数据不会写入文件
* */
public class Demo1 {
    public static void main(String[] args) throws Exception {

        //1、创建FileWriter对象
        try (FileWriter fw = new FileWriter("Day06/src/IO/Writer/outputDemo")) {
            //2、写入数据
            // 可以写入字符
            fw.write(97);//a
            fw.write('你');
            fw.write('好');
            fw.write("hello world");

            fw.write("\r\n");

            //可以写入字符数组
            char[] chars = {'a', 'b', 'c'};
            fw.write(chars);//abc
            fw.write("\r\n");
            fw.write(chars, 1, 2);//bc

            fw.write("\r\n");

            //可以写入字符串
            String s = "hello world";
            fw.write(s);//
            fw.write("\r\n");
            fw.write(s, 6, 5);

            fw.write("\r\n");

            //可以写入字符串数组
            String[] ss = {"hello", "world"};
            fw.write(Arrays.toString(ss));
            //刷新缓冲区
            fw.flush();
        }catch (Exception e){
            e.printStackTrace();
        }
    }
}
